package com.grass.p019lv.activity;

import android.view.View;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.alibaba.android.arouter.launcher.ARouter;
import com.androidx.p013lv.base.Constance;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.BaseActivity;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.androidx.p013lv.base.utils.UiUtils;
import com.androidx.p013lv.base.view.StatusControlLayout;
import com.grass.p019lv.R;
import com.grass.p019lv.adapter.LikeMessageAdapter;
import com.grass.p019lv.bean.DynamicLike;
import com.grass.p019lv.bean.MessageDynamicLike;
import com.grass.p019lv.databinding.ActivityLikeMessageLayoutBinding;
import com.grass.p019lv.viewmodel.MessageModel;
import com.gyf.immersionbar.ImmersionBar;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;
import java.util.List;

/* renamed from: com.grass.lv.activity.LikeMessageActivity */
public class LikeMessageActivity extends BaseActivity<ActivityLikeMessageLayoutBinding> implements OnRefreshLoadMoreListener, ItemClickListener {
    private LikeMessageAdapter adapter;
    private MessageModel model;
    private int page = 1;

    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public int setLayout() {
        return R.layout.activity_like_message_layout;
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this).titleBar(((ActivityLikeMessageLayoutBinding) this.binding).toolBar).init();
    }

    /* access modifiers changed from: protected */
    @Override // com.androidx.p013lv.base.p015ui.BaseActivity
    public void initView() {
        super.initView();
        ((ActivityLikeMessageLayoutBinding) this.binding).setClick(new OnClick());
        this.model = (MessageModel) new ViewModelProvider(this).get(MessageModel.class);
        LikeMessageAdapter likeMessageAdapter = new LikeMessageAdapter();
        this.adapter = likeMessageAdapter;
        likeMessageAdapter.setItemListener(this);
        ((ActivityLikeMessageLayoutBinding) this.binding).include.recycler.setPadding(0, UiUtils.dp2px(10), 0, 0);
        ((ActivityLikeMessageLayoutBinding) this.binding).include.recycler.setLayoutManager(new LinearLayoutManager(this));
        ((ActivityLikeMessageLayoutBinding) this.binding).include.recycler.setAdapter(this.adapter);
        ((ActivityLikeMessageLayoutBinding) this.binding).include.refresh.setOnRefreshListener(this);
        ((ActivityLikeMessageLayoutBinding) this.binding).include.refresh.setOnLoadMoreListener(this);
        ((ActivityLikeMessageLayoutBinding) this.binding).include.statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.grass.p019lv.activity.LikeMessageActivity.View$OnClickListenerC28721 */

            public void onClick(View view) {
                LikeMessageActivity.this.page = 1;
                ((ActivityLikeMessageLayoutBinding) LikeMessageActivity.this.binding).setStatus(2);
                LikeMessageActivity.this.model.dynamicLikeLive(LikeMessageActivity.this.page);
            }
        });
        this.model.getDynamicLikeLive().observe(this, new C2956a(this));
        ((ActivityLikeMessageLayoutBinding) this.binding).setStatus(2);
        this.model.dynamicLikeLive(this.page);
    }

    public /* synthetic */ void lambda$initView$0$LikeMessageActivity(BaseRes baseRes) {
        hideLoading();
        hideLoading();
        if (baseRes.getCode() == 200) {
            MessageDynamicLike messageDynamicLike = (MessageDynamicLike) baseRes.getData();
            if (this.page == 1) {
                if (messageDynamicLike == null || messageDynamicLike.getData() == null || messageDynamicLike.getData().size() == 0) {
                    ((ActivityLikeMessageLayoutBinding) this.binding).setStatus(4);
                    return;
                }
                List<DynamicLike> data = messageDynamicLike.getData();
                this.adapter.setDomain(messageDynamicLike.getDomain());
                this.adapter.setData(data);
                if (data.size() < 30) {
                    ((ActivityLikeMessageLayoutBinding) this.binding).setStatusRefresh(2);
                }
            } else if (messageDynamicLike == null || messageDynamicLike.getData() == null || messageDynamicLike.getData().size() == 0) {
                ((ActivityLikeMessageLayoutBinding) this.binding).setStatusRefresh(2);
            } else {
                List<DynamicLike> data2 = messageDynamicLike.getData();
                this.adapter.setDatasInEnd(data2);
                if (data2.size() < 30) {
                    ((ActivityLikeMessageLayoutBinding) this.binding).setStatusRefresh(2);
                }
            }
        } else if (this.page == 1) {
            ((ActivityLikeMessageLayoutBinding) this.binding).setStatus(1);
        } else {
            ToastUtils.getInstance().showWrong(baseRes.getMsg());
        }
    }

    public void hideLoading() {
        ((ActivityLikeMessageLayoutBinding) this.binding).setStatus(0);
        ((ActivityLikeMessageLayoutBinding) this.binding).setStatusRefresh(1);
    }

    public static void showStatusView(StatusControlLayout statusControlLayout, int i) {
        statusControlLayout.showStatusView(i);
    }

    public static void refreshStatus(SmartRefreshLayout smartRefreshLayout, int i) {
        if (i == 1) {
            smartRefreshLayout.finishLoadMore();
            smartRefreshLayout.finishRefresh();
        }
        if (i == 2) {
            smartRefreshLayout.finishLoadMoreWithNoMoreData();
        }
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        int i = this.page + 1;
        this.page = i;
        this.model.dynamicLikeLive(i);
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.page = 1;
        this.model.dynamicLikeLive(1);
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (!isOnClick()) {
            ARouter.getInstance().build(Constance.USER_INFO_ACTIVITY).withInt("type", 1).withInt(Key.USER_ID, ((DynamicLike) this.adapter.getDataInPosition(i)).getUserId()).navigation();
        }
    }

    /* renamed from: com.grass.lv.activity.LikeMessageActivity$OnClick */
    public class OnClick {
        public OnClick() {
        }

        public void btnBack() {
            LikeMessageActivity.this.finish();
        }
    }

    /* access modifiers changed from: protected */
    @Override // androidx.appcompat.app.AppCompatActivity, androidx.fragment.app.FragmentActivity, com.androidx.p013lv.base.p015ui.BaseActivity
    public void onDestroy() {
        MessageModel messageModel = this.model;
        if (messageModel != null) {
            messageModel.cancelHttp();
        }
        super.onDestroy();
    }
}
